﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Threading;

namespace DrivingAlarm
{
    static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new FrmMain());
            //bool bCreate;
            ////保证程序只能运行一个
            //using (Mutex mu = new Mutex(true, Application.ProductName, out bCreate))
            //{
            //    if (bCreate)
            //    {
            //        RunApp();
            //    }
            //    else
            //    {
            //        MessageBox.Show("程序已经运行!");
            //    }
            //}
        }
        /// <summary>
        /// 运行App
        /// </summary>
        static void RunApp()
        {
            try
            {
                //设置应用程序处理异常方式：ThreadException处理
                Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
                //处理UI线程异常
                Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
                //处理非UI线程异常
                AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new FrmMain());
            }
            catch //(Exception ex)
            {
                //Funcs.WriteLog(ex);
            }
        }

#region 错误处理
        static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
        {
            //string str = CDAL.CSftLog.GetExceptionMsg(e.Exception, e.ToString());
            //LogManager.WriteLog(str);
            //Funcs.WriteLog(str);
        }
        static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            //string str = CDAL.CSftLog.GetExceptionMsg(e.ExceptionObject as Exception, e.ToString());
            //LogManager.WriteLog(str);
            //Funcs.WriteLog(str);
        }
#endregion
    }
}
